package com.ljw.food_order_server.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ljw.food_order_server.entity.MyWindow;
import com.ljw.food_order_server.mapper.MyWindowMapper;
import com.ljw.food_order_server.service.MyWindowService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ljw.food_order_server.vo.WindowStream;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 窗口 服务实现类
 * </p>
 *
 * @author ljw
 * @since 2021-07-31
 */
@Service
public class MyWindowServiceImpl extends ServiceImpl<MyWindowMapper, MyWindow> implements MyWindowService {

    public List<MyWindow> getWindows(Integer positionId){
        QueryWrapper<MyWindow> windowQueryWrapper = new QueryWrapper<>();
        windowQueryWrapper.eq("position_id",positionId);
        List<MyWindow> list = this.list(windowQueryWrapper);
        return list;
    }

    public List<WindowStream> getStream(int positionId){
        //获取所有窗口
        QueryWrapper<MyWindow> windowQueryWrapper = new QueryWrapper<>();
        windowQueryWrapper.eq("position_id",positionId);
        List<MyWindow> windows = this.list(windowQueryWrapper);
        List<WindowStream> windowStreams = new ArrayList<>();
        for(MyWindow window: windows){
            int randomNumber = (int) Math.floor(Math.random() * 70);
            WindowStream stream = new WindowStream();
            stream.setWindowId(window.getWindowId());
            stream.setWindowName(window.getWindowName());
            stream.setPersonNumber(randomNumber);
            windowStreams.add(stream);
        }
        return windowStreams;
    }

}
